<%@ Page language="vb" CodeFile="printVehicle.aspx.vb" Inherits="printVehicle_aspx_vb" %>

<%
    rowNumber = 1
    vehicleID = Request.QueryString("vehicleID")
    vehicleID = CLng(vehicleID)
    If (Request.QueryString("do")) = Nothing Then 
        subDo = Request.QueryString("subDo")
        OverPrint()
        Response.Write("<div class=noprint>")
        Response.Write("<table>")
        Response.Write("<tr>")
        Response.Write("<td class='headline'>")
        Response.Write("<form>")
        Response.Write("<input type='button' onClick='javascript:print();' value='Print'>&nbsp; ")
        Response.Write("</form>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Response.Write("</div>")
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='100%'>")
        Response.Write("<tr><td width='100%' colspan='3' class='headlineBig' align='center'>LEASING&nbsp; INFORMATION</font></td></tr>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
        Response.Write("<tr><td class='headline' colspan='3'>VEHICLE DETAILS<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select v.regnr, v.vinNumber, v.contractNumber, v.cylinderVolume, v.consumedDistance, v.discountPercent, v.completed, v.active, v.date, b.brand, m.model, u.username From (((tblVehicle v INNER JOIN tblBrand b ON b.brandID = v.brandID) INNER JOIN tblModel m ON m.modelID = v.modelID) INNER JOIN tblUser u ON u.userID = v.userID) Where v.vehicleID = " & vehicleID & "")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>ERROR</font></td></tr>")
        Else
            regnr = RecSet.Fields("regnr").Value
            vinNumber = RecSet.Fields("vinNumber").Value
            contractNumber = RecSet.Fields("contractNumber").Value
            cylinderVolume = RecSet.Fields("cylinderVolume").Value
            consumedDistance = RecSet.Fields("consumedDistance").Value
            discountPercent = RecSet.Fields("discountPercent").Value
            completed = RecSet.Fields("completed").Value
            active = RecSet.Fields("active").Value
            __date = RecSet.Fields("date").Value
            brand = RecSet.Fields("brand").Value
            model = RecSet.Fields("model").Value
            username = RecSet.Fields("username").Value
            If CInt(completed) = 0 Then 
                completed = "No"
            Else
                completed = "Yes"
            End IF
            If CInt(active) = 0 Then 
                active = "No"
            Else
                active = "Yes"
            End IF
            Response.Write("<tr><td class='printBold'>Car make:</td><td align='right' class='printRegular'>" & brand & " " & model & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Licence number:</td><td align='right' class='printRegular'>" & regnr & "</td></tr>")
            Response.Write("<tr><td class='printBold'>VIN-number:</td><td align='right' class='printRegular'>" & vinNumber & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Contract number:</td><td align='right' class='printRegular'>" & contractNumber & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Cylindervolume:</td><td align='right' class='printRegular'>" & cylinderVolume & " cc</td></tr>")
            Response.Write("<tr><td class='printBold'>Consumed distance:</td><td align='right' class='printRegular'>" & consumedDistance & " km</td></tr>")
            Response.Write("<tr><td class='printBold'>Discount percent:</td><td align='right' class='printRegular'>" & discountPercent & " %</td></tr>")
            Response.Write("<tr><td class='printBold'>Lease contract active:</td><td align='right' class='printRegular'>" & active & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Lease contract complete:</td><td align='right' class='printRegular'>" & completed & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Administrated by:</td><td align='right' class='printRegular'>" & username & "</td></tr>")
            Response.Write("<tr><td class='printBold'>First created:</td><td align='right' class='printRegular'>" & Left(__date, 10) & "</td></tr>")
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='20'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
        Response.Write("<tr><td class='headline' colspan='5'>PRODUCT & PRICING DETAILS<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select pr.priceListDuration, pr.priceListDistance, p.product From ((tblVehicle v INNER JOIN tblPriceList pr ON pr.priceListID = v.priceListID) INNER JOIN tblProduct p ON p.productID = pr.productID) Where v.vehicleID = " & vehicleID & "")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>ERROR</font></td></tr>")
        Else
            priceListDuration = RecSet.Fields("priceListDuration").Value
            priceListDistance = RecSet.Fields("priceListDistance").Value
            product = RecSet.Fields("product").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        additionalProductCount = 0
        dbOpen()
        RecSet = Conn.Execute("Select ap.additionalProduct From (tblAdditionalProductVehicleContent apvc INNER JOIN tblAdditionalProduct ap ON ap.additionalProductID = apvc.additionalProductID) Where apvc.vehicleID = " & vehicleID & "")
        If RecSet.EOF Then 
            additionalProduct = "N/A"
        Else
            Do Until RecSet.EOF
                dbAdditionalProduct = RecSet.Fields("additionalProduct").Value
                If additionalProductCount = 0 Then 
                    additionalProduct = dbAdditionalProduct
                Else
                    additionalProduct = additionalProduct & "<br>" & dbAdditionalProduct
                End IF
                additionalProductCount = additionalProductCount + 1
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td class='formBold'>Product:</td><td align='right'>" & product & "</td></tr>")
        Response.Write("<tr><td class='formBold' valign='top'>Additional Product(s):</td><td align='right' valign='top'>" & additionalProduct & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Duration:</td><td align='right'>" & priceListDuration & " months</td></tr>")
        Response.Write("<tr><td class='formBold'>Driving distance:</td><td align='right'>" & priceListDistance & " km</td></tr>")
        Response.Write("<tr><td colspan='5'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
        Response.Write("<tr><td class='headline' colspan='3'>DRIVER DETAILS<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select d.driverID, d.driver, d.city, d.areaCode, d.telephone, d.email, d.date, c.country, u.username From (((tblVehicle v INNER JOIN tblDriver d ON d.driverID = v.driverID) INNER JOIN tblCountry c ON c.countryID = d.countryID) INNER JOIN tblUser u ON u.userID = d.userID) Where v.vehicleID = " & vehicleID & "")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>ERROR</font></td></tr>")
        Else
            driverID = RecSet.Fields("driverID").Value
            driver = RecSet.Fields("driver").Value
            city = RecSet.Fields("city").Value
            areaCode = RecSet.Fields("areaCode").Value
            telephone = RecSet.Fields("telephone").Value
            email = RecSet.Fields("email").Value
            __date = RecSet.Fields("date").Value
            country = RecSet.Fields("country").Value
            username = RecSet.Fields("username").Value
            Response.Write("<tr><td class='printBold'>Driver:</td><td align='right' class='printRegular'>" & driver & "</td></tr>")
            Response.Write("<tr><td class='printBold'>City:</td><td align='right' class='printRegular'>" & city & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Areacode:</td><td align='right' class='printRegular'>" & areaCode & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Telephone:</td><td align='right' class='printRegular'>" & telephone & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Email:</td><td align='right' class='printRegular'><a href='mailto:" & email & "'>" & email & "</a></td></tr>")
            Response.Write("<tr><td class='printBold'>Country:</td><td align='right' class='printRegular'>" & country & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Administrated by:</td><td align='right' class='printRegular'>" & username & "</td></tr>")
            Response.Write("<tr><td class='printBold'>First created:</td><td align='right' class='printRegular'>" & Left(__date, 10) & "</td></tr>")
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='20'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
        Response.Write("<tr><td class='headline' colspan='5'>LEASE TAKER DETAILS<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select c.clientID, c.client, c.city, c.areaCode, c.telephone, c.email, c.cin, c.date, co.country, u.username From (((tblVehicle v INNER JOIN tblClient c ON c.clientID = v.clientID) INNER JOIN tblCountry co ON co.countryID = c.countryID) INNER JOIN tblUser u ON u.userID = c.userID) Where v.vehicleID = " & vehicleID & "")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>ERROR</font></td></tr>")
        Else
            intClientID = RecSet.Fields("clientID").Value
            client = RecSet.Fields("client").Value
            city = RecSet.Fields("city").Value
            areaCode = RecSet.Fields("areaCode").Value
            telephone = RecSet.Fields("telephone").Value
            email = RecSet.Fields("email").Value
            cin = RecSet.Fields("cin").Value
            __date = RecSet.Fields("date").Value
            country = RecSet.Fields("country").Value
            username = RecSet.Fields("username").Value
            Response.Write("<tr><td class='printBold'>Lease taker:</td><td align='right' class='printRegular'>" & client & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Corporate Identity Number:</td><td align='right' class='printRegular'>" & cin & "</td></tr>")
            Response.Write("<tr><td class='printBold'>City:</td><td align='right' class='printRegular'>" & city & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Areacode:</td><td align='right' class='printRegular'>" & areaCode & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Telephone:</td><td align='right' class='printRegular'>" & telephone & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Email:</td><td align='right' class='printRegular'><a href='mailto:" & email & "'>" & email & "</a></td></tr>")
            Response.Write("<tr><td class='printBold'>Country:</td><td align='right' class='printRegular'>" & country & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Administrated by:</td><td align='right' class='printRegular'>" & username & "</td></tr>")
            Response.Write("<tr><td class='printBold'>First created:</td><td align='right' class='printRegular'>" & Left(__date, 10) & "</td></tr>")
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='5'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
        Response.Write("<tr><td class='headline' colspan='3'>CAR DEALER DETAILS<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select d.dealerID, d.dealer, d.city, d.areaCode, d.telephone, d.email, d.date, co.country, u.username From (((tblVehicle v INNER JOIN tblDealer d ON d.dealerID = v.dealerID) INNER JOIN tblCountry co ON co.countryID = d.countryID) INNER JOIN tblUser u ON u.userID = d.userID) Where v.vehicleID = " & vehicleID & "")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>ERROR</font></td></tr>")
        Else
            dealerID = RecSet.Fields("dealerID").Value
            dealer = RecSet.Fields("dealer").Value
            city = RecSet.Fields("city").Value
            areaCode = RecSet.Fields("areaCode").Value
            telephone = RecSet.Fields("telephone").Value
            email = RecSet.Fields("email").Value
            __date = RecSet.Fields("date").Value
            country = RecSet.Fields("country").Value
            username = RecSet.Fields("username").Value
            Response.Write("<tr><td class='printBold'>Car dealer:</td><td align='right' class='printRegular'>" & dealer & "</td></tr>")
            Response.Write("<tr><td class='printBold'>City:</td><td align='right' class='printRegular'>" & city & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Areacode:</td><td align='right' class='printRegular'>" & areaCode & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Telephone:</td><td align='right' class='printRegular'>" & telephone & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Email:</td><td align='right' class='printRegular'><a href='mailto:" & email & "'>" & email & "</a></td></tr>")
            Response.Write("<tr><td class='printBold'>Country:</td><td align='right' class='printRegular'>" & country & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Administrated by:</td><td align='right' class='printRegular'>" & username & "</td></tr>")
            Response.Write("<tr><td class='printBold'>First created:</td><td align='right' class='printRegular'>" & Left(__date, 10) & "</td></tr>")
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='20'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
        Response.Write("<tr><td class='headline' colspan='5'>PARTNER DETAILS<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select p.partnerID, p.partnerName, p.street, p.zipcode, p.city, p.date, co.country From ((tblVehicle v INNER JOIN tblPartner p ON p.partnerID = v.partnerID) INNER JOIN tblCountry co ON co.countryID = p.countryID) Where v.vehicleID = " & vehicleID & "")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>ERROR</font></td></tr>")
        Else
            partnerID = RecSet.Fields("partnerID").Value
            partnerName = RecSet.Fields("partnerName").Value
            street = RecSet.Fields("street").Value
            zipcode = RecSet.Fields("zipcode").Value
            city = RecSet.Fields("city").Value
            __date = RecSet.Fields("date").Value
            country = RecSet.Fields("country").Value
            Response.Write("<tr><td class='printBold'>Partner:</td><td align='right' class='printRegular'>" & partnerName & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Street:</td><td align='right' class='printRegular'>" & street & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Zipcode:</td><td align='right' class='printRegular'>" & zipcode & "</td></tr>")
            Response.Write("<tr><td class='printBold'>City:</td><td align='right' class='printRegular'>" & city & "</td></tr>")
            Response.Write("<tr><td class='printBold'>Country:</td><td align='right' class='printRegular'>" & country & "</td></tr>")
            Response.Write("<tr><td class='printBold'>First created:</td><td align='right' class='printRegular'>" & Left(__date, 10) & "</td></tr>")
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='5'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    End IF
%>
